const HtmlWebpackPlugin = require('html-webpack-plugin');

const webpack = require('webpack');

const path = require('path');

const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");


module.exports = {
  entry: {
    axios: ["axios"],
    jquery: ["jquery"],
    "v-distpicker": ["v-distpicker"],
    "vue-lazyload": ["vue-lazyload"],
    moment: ["moment"],
    quanjiatong: ["vue", "vue-router", "vuex"],
    bundle: "./src/main.js" //千万不要忘记了哦
  },
  output: {
    path: path.join(__dirname, "dist"),
    filename: 'js/[name].js'
  },
  module: {
    rules: [{
        test: /\.vue$/,
        use: 'vue-loader'
      },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({//抽离
          fallback: "style-loader",
          use: {
            loader: 'css-loader',
            options: {
              minimize: true,//压缩
              publicPath:'dist/css'
            }
          },
        })
      },
      {
        test: /\.(ttf|woff|eot|svg|jpg|gif|png)$/,
        use: [{
          loader: 'url-loader',
          options: {
            limit: 3000,
            name: 'statics/img/[name]-[hash:8].[ext]'
          }
        }]
      },
      {
        //使用babel必须加的
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "babel-loader"
      }
    ]
  },
  resolve: {
    extensions: [".vue", ".js", ".json"]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './template.html',
      minify: {
        removeComments: true, //删除注释
        minifyCSS: true, //压缩css
        minifyJS: true, //压缩js
        collapseWhitespace: true //压缩空格
      }
    }),
    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: "jquery"
    }),
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify('production')
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false,
        drop_debugger: true, //去除调试 
        drop_console: true //去除打印
      },
      output: {
        comments: false //去除copyright
      }
    }),
    //抽离第三方包的，这里不要写bundle.js
    new webpack.optimize.CommonsChunkPlugin({
      name: [
        "quanjiatong",
        "vue-lazyload",
        "v-distpicker",
        "moment",
        "jquery",
        "axios"
      ],
      // name: ['jquery', 'vue-moment','quanjiatong','axios','v-distpicker','vue-lazyload'],
      // filename: "vendor.js"
      // (给 chunk 一个不同的名字)

      minChunks: Infinity
      // (随着 entry chunk 越来越多，
      // 这个配置保证没其它的模块会打包进 vendor chunk)
    }),
    new CleanWebpackPlugin("dist"),
    new ExtractTextPlugin("css/styles.css"),
    new webpack.ContextReplacementPlugin(/moment[\\\/]locale$/, /^\.\/(zh-cn|en-gb)$/)
  ]
}